import {compareDateString} from 'ph-datetime-util'
export const Mode = {
    datetime:0,
    date:1,
    month:2,
    year:3,
    time:4
} as Record<string,number>
export const Format:{[k:string]:string} = {
    0:"yyyy-MM-dd hh:mm:ss",
    1:"yyyy-MM-dd",
    2:"yyyy-MM",
    3:"yyyy",
    4:"hh:mm:ss"
} as Record<number,string>
export function datetimeRangeValid(start?:string,end?:string,min?:string,max?:string):string|boolean{
    if(min&&max){
        if(
            start&&(!compareDateString(start,min)||!compareDateString(max,start))||
            end&&(!compareDateString(end,min)||!compareDateString(max,end))
        )
            return `请录入${min}-${max}范围的日期时间`
    }
    else if(min){
        if(
            (start&&!compareDateString(start,min))||
            (end&&!compareDateString(end,min))
        )
            return `请录入${min}之后的日期时间`
    }
    else if(max){
        if(
            (start&&!compareDateString(max,start))||
            (end&&!compareDateString(max,end))
        )
            return `请录入${max}之前的日期时间`
    }
    if(!start)
        return "请录入开始日期时间"
    if(!end)
        return "请录入结束日期时间"
    if(!compareDateString(end,start))
        return "开始日期时间不能大于结束日期时间"
    return true
}